<template>
  <div class="app-container">
    <!-- 查询表单-->
    <!--element-ui的 date-picker组件默认绑定的时间值是默认世界标准时间，和中国时间差8小时
          设置 value-format="yyyy-MM-dd HH:mm:ss" 改变绑定的值-->
    <div id="content">
      <i class="el-icon-menu">筛选</i>
      <p />
      <el-form
        :inline="true"
        :model="customerShowQuery"
        class="demo-form-inline"
      >
        <el-form-item label="输入搜索">
          <el-input
            v-model="customerShowQuery.name"
            placeholder="请输入手机号查询"
          ></el-input>
        </el-form-item>
        <el-form-item label="上传时间">
          <el-date-picker
            v-model="customerShowQuery.startTime"
            type="datetime"
            placeholder="选择开始日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            default-time="00:00:00"
          />
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="customerShowQuery.endTime"
            type="datetime"
            placeholder="选择结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            default-time="00:00:00"
          />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getLine()"
          >筛选</el-button
        >
        <el-button type="default" @click="resetData()">清空筛选条件</el-button>
      </el-form>
      <el-row>
        <el-col>
          <div class="grid-content bg-purple">
            <i class="el-icon-menu">教育头条列表</i>
          </div>
        </el-col>
        <el-col>
          <div class="grid-content bg-purple-light"></div>
        </el-col>

        
      </el-row>
      <p />
      <!--表格-->
      <el-table
        v-loading="listLoading"
        :data="list"
        @selection-change="handleSelectionChange"
        element-loading-text="数据加载中"
        border
        fit
        stripe
        highlight-current-row
        style="width: 100%"
      >
        <!--数据展示-->
        <el-table-column type="selection" width="65"></el-table-column>
        <el-table-column prop="userId" label="用户id" width="130" />
        <el-table-column prop="vxName" label="微信名称" width="160"/>
        <el-table-column prop="telNumber" label="手机号" width="200" />
        <el-table-column prop="registrationTime" label="注册时间" width="260" />
        <el-table-column prop="grade" label="会员等级" width="160" />
        <el-table-column prop="status" label="禁用账户" width="150" align="center">
          <template slot-scope="scope">
          <el-tooltip :content="'Switch value: ' + scope.row.accountState" placement="none" >
            <el-switch
              v-model="scope.row.accountState"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="1"
              :inactive-value="2"
              active-text="开启"

              inactive-text="禁用"
              @change="stopOrOpenOne(scope.row.userId,scope.row.accountState)"
            >
            </el-switch>
          </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="300" align="center">
          <template slot-scope="scope">
            <router-link :to="'/editCustomer/' + scope.row.userId">
              <el-button type="primary" size="mini" icon="el-icon-edit"
                >用户详情</el-button
              >
            </router-link>
            <el-button
              type="danger"
              size="mini" 
              icon="el-icon-delete"
              @click="removeDataById(scope.row.userId)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <span
        @click="deleteBatches()"
        style="
          cursor: pointer;
          color: #999999;
          font-family: '思源黑体';
          font-weight: 400;
          font-style: normal;
          font-size: 14px;
        "
        >批量删除</span
      >
      <!-- 分页 -->
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        background
        style="padding: 30px 0; text-align: center"
        layout="total, prev, pager, next, jumper"
        @current-change="getLine"
      />
    </div>
  </div>
</template>
<script>
//引入调用headlineShow.js文件
import customerShowApi from "@/api/customerShow";

export default {
  //写核心代码位置
  // data:{
  // },
  data() {
    //定义变量和初始值
    return {
      listLoading: true, // 是否显示loading信息
      list: null, //查询之后接口返回集合
      page: 1, //当前页
      limit: 10, //每页记录数
      total: 0, //总记录数
      customerShowQuery: {
        name: "",
        startTime: "",
        endTime: "",
      }, //条件封装对象
      checkList: [],
      status:0,
      putId: []
    };
  },
  created() {
    //页面渲染之前执行，一般调用methods定义的方法
    //调用
    this.getLine();
  },
  mounted() {
    this.listLoading = false;
  },
  methods: {
    //创建具体的方法，调用headlineShow.js定义的方法
    //获取轮播图列表的方法,默认是第一页
    getLine(page = 1) {
      this.page = page;
      customerShowApi
        .getCustomerShowListPage(this.page, this.customerShowQuery)
        .then((response) => {
          //请求成功
          //response接口返回的数据
          this.list = response.object.list;
          this.total = response.object.total;
        });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      //获取所有选中项的gh(工号)属性的值
      this.checkList = selection.map((item) => item.userId);
    },
    resetData() {
      //清空的方法
      //表单输入项数据清空
      this.customerShowQuery = {};
      //查询所有讲师数据
      this.getLine();
      this.$message({
        type: "success",
        message: "清空成功!",
      });
    },
    stopOrOpenOne(id,accountState){
     
      customerShowApi.stopOrOpen(id, accountState)
      .then((response) => {
          
        //删除成功
        //提示信息
            this.$message({
              type: "success",
              message: "操作成功!",
           })
        });
    },
    //删除头条的方法
    removeDataById(id) {
      this.putId=[]
      this.putId.push(id)
      this.$confirm(
        "此操作将会删除数据,您将无法找回 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          customerShowApi.deleteBatchesById(this.putId).then((response) => {
            //删除成功
            //提示信息
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            //回到列表页面
            this.getLine();
          });
        })
        .catch((e) => {
          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    },
    //批量删除头条的方法
    deleteBatches() {
      this.$confirm(
        "此操作将会删除数据,您无法找回 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用删除的方法
          
          customerShowApi
            .deleteBatchesById(this.checkList)
            .then((response) => {
              //删除成功
              //提示信息
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              //回到列表页面
              this.getLine();
            });
        })
        .catch((e) => {
          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    },
  },
};
</script>
<style>
#content {
  width: 80%;
  margin: 0 auto;
}
.el-row .el-col-24 {
  width: 150px;
}
.el-col-24:nth-child(3),
.el-col-24:nth-child(4) {
  float: right;
}
</style>